package com.xinqi.modules.prepare.folder.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.folder.client.PrepareFileFolderClient;
import com.xinqi.modules.prepare.folder.dto.req.PrepareFileFolderCreateDTO;
import com.xinqi.modules.prepare.folder.dto.req.PrepareFileFolderQueryDTO;
import com.xinqi.modules.prepare.folder.dto.req.PrepareFileFolderUpdateDTO;
import com.xinqi.modules.prepare.folder.dto.rsp.PrepareFileFolderResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 备课区文件夹降级处理
 *
 * @author: system
 * @date: 2023/03/19
 */
@Slf4j
@Component
public class PrepareFileFolderFallbackFactory implements FallbackFactory<PrepareFileFolderClient> {

    @Override
    public PrepareFileFolderClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new PrepareFileFolderClient() {
            @Override
            public R<PageInfo<PrepareFileFolderResultDTO>> page(PrepareFileFolderQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<PrepareFileFolderResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(PrepareFileFolderCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, PrepareFileFolderUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
